package plugin;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import persistence.DataPersistor;

public class ComSearchUPCPluginTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		DataPersistor.instance().init("-serial");
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() throws Exception {
		IProductIDPlugin plugin = new ComSearchUPCPlugin();
		String test1 = plugin.identifyProduct("031200016058"); //valid
		assertEquals(test1, "Ocean Spray, Jellied Cranberry Sauce, 14oz Can (Pack of 6)");
		
		String test2 = plugin.identifyProduct("016000275164"); //valid
		assertEquals(test2, "Golden Grahams, 12-Ounce Boxes (Pack of 4)");
		
		try {
			plugin.identifyProduct("000000000001"); //invalid
			fail("attempted to identify an invalid barcode");
		}
		catch (Exception e) {
			//success!
		}
		
		try {
			plugin.identifyProduct("531974629473"); //valid, but no description
			fail("didn't throw an exception on a barcode not in the system");
		}
		catch (Exception e) {
			//success!
		}
	}

}
